package com.zhuangyuan.cloud.data;

import com.zhuangyuan.cloud.data.entities.Category;
import com.zhuangyuan.cloud.data.repository.sqlite.CateCategoryRepository;
import com.zhuangyuan.cloud.data.repository.sqlite.CateRepository;
import com.zhuangyuan.cloud.data.service.CategoryService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.List;

@SpringBootTest(classes = App.class)
@RunWith(SpringRunner.class)
public class SqliteTester {
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private CateRepository cateRepository;
    @Autowired
    private CateCategoryRepository cateCategoryRepository;

    @Test
//    @Transactional(rollbackFor = Exception.class)
    public void prepareCategories(){
        Category p1 = new Category("热菜",0,"RC",null);
        List<Category> p1children = new ArrayList<>();
//        p1children.add(new Category("红烧臭鳜鱼",1,"HSCGY",p1.getId()));
//        p1children.add(new Category("红烧排骨",1,"HSPG",p1.getId()));
//        p1children.add(new Category("臭豆腐",1,"CDF",p1.getId()));
//        p1children.add(new Category("红烧鸭掌",1,"HSYZ",p1.getId()));
        categoryService.add(p1);
        categoryService.addAll(p1children);

        Category p2 = new Category("凉菜",0,"LC",null);
        List<Category> p2children = new ArrayList<>();
//        p2children.add(new Category("凉拌黄瓜",1,"LBHG",p2.getId()));
//        p2children.add(new Category("凉拌椿树头",1,"LBCST",p2.getId()));
        categoryService.add(p2);
        categoryService.addAll(p2children);

        Category p3 = new Category("汤",0,"T",null);
        List<Category> p3children = new ArrayList<>();
//        p3children.add(new Category("西红柿鸡蛋汤",1,"XHSJDT",p3.getId()));
//        p3children.add(new Category("老母鸡汤",1,"LMJT",p3.getId()));
        categoryService.add(p3);
        categoryService.addAll(p3children);

    }

    @Test
    public void testFindAll(){
        List<Category> list = categoryService.list();
        list.forEach(m->categoryService.delete(m));
        System.out.println(list.size());
    }

}
